import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ValueBuilderPage extends GetView {

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text('ValueBuilderPage'),
        centerTitle: true,
      ),

      body: SafeArea(
        child: ListView(
          children: [
            Text(
              '- 简化的状态组件\n- 不支持跨页面的状态管理',
              style: Theme.of(context).textTheme.headline5
            ),
            Divider(),

            Center(
              child: ValueBuilder<int?>(
                initialValue: 1,
                builder: (value, updater) {
                  return Column(
                    children: [
                      Text(
                        'count: '+value.toString(),
                        style: Theme.of(context).textTheme.headline5
                      ),
                      ElevatedButton(
                        onPressed: () {
                          updater(value! + 1);
                        }, 
                        child: Icon(Icons.add)
                      )
                    ],
                  );
                },
                onUpdate: (value) => print("数据更新了 $value"),
                onDispose: () => print('页面关闭'),
              ),
            )
          ]
        )
      )
    );
  }
}